//
//  HomePayListCell.m
//  LocalGoods2
//
//  Created by 黄晓冬 on 2018/10/25.
//  Copyright © 2018年 Xiaodong Huang. All rights reserved.
//

#import "HomePayListCell.h"
#import "Header.h"
#import "PayListCollectionViewCell.h"

#define collectionHeight 787 // collectionview高度
static NSString *PayListCollectionCell_id = @"payListCollectionCell_id";
@interface HomePayListCell ()<UICollectionViewDelegate, UICollectionViewDataSource>

@property (nonatomic, strong) UICollectionView *collectionView;
@end

@implementation HomePayListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setUpUI];
    }
    
    return self;
}

- (void)setUpUI {
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake((SCREAM_WEIGHT-30)/2, (collectionHeight*Proportion_375-40)/3);
    flowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 0, 10);
    flowLayout.minimumLineSpacing = 10;
    flowLayout.minimumInteritemSpacing = 10;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.contentView addSubview:_collectionView];
    
    [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.offset(0);
        make.height.offset(collectionHeight*Proportion_375);
    }];
    
    [_collectionView registerClass:[PayListCollectionViewCell class] forCellWithReuseIdentifier:PayListCollectionCell_id];
}


//MARK: - UICollectionViewDelegate, UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 6;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    PayListCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:PayListCollectionCell_id forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if (self.delegate && [self.delegate respondsToSelector:@selector(homePayListDidSelectCommodityID:)]) {
        // 传入商品id
        [self.delegate homePayListDidSelectCommodityID:0];
    }
}
@end





























